# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=openvr
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.12.5
pkgrel=1
pkgdesc="API and SDK that allows access to VR hardware from multiple vendors (mingw-w64)"
arch=('any')
url="https://github.com/ValveSoftware/openvr/"
license=("BSD3")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-python")
source=(${_realname}-${pkgver}.tar.gz::https://github.com/ValveSoftware/openvr/archive/v${pkgver}.tar.gz
        001-_WIN32-macros.patch
        002-install-headers.patch
        003-mingw-library-name.patch
        004-install-location.patch
        cxx_header_generator.py)
sha256sums=('f3cdbaa946688553638e6d65978f156311c9b08825316198d925f5eade6cfeb7'
            '51c697a176847aaead97f185422f844091b4d4257b84074ec1c6c8a466c74283'
            '10ece7ce59e78747c24ac98bb891d65ab6e57a888094a1fad5e87b56dff5ae10'
            '103ec4394f2fef820276906397011a498396694999e492c14ce0fda19f6d1014'
            '3fe7b4420a52ecf4233558ef5dbcc56f2abf35e204c90fbcefd13e0127a3938f'
            '739d0f4eeb8d83d2236d2174fbfac209ea20009bcaabba455c9b31301c14acfe')
noextract=(${_realname}-${pkgver}.tar.gz)

prepare() {
  [[ -d ${srcdir}/openvr-${pkgver} ]] && rm -rf ${srcdir}/openvr-${pkgver}
  tar -xzf ${srcdir}/${_realname}-${pkgver}.tar.gz -C ${srcdir} || true
  
  cd openvr-${pkgver}
  patch -p1 -i ${srcdir}/001-_WIN32-macros.patch
  patch -p1 -i ${srcdir}/002-install-headers.patch
  patch -p1 -i ${srcdir}/003-mingw-library-name.patch
  patch -p1 -i ${srcdir}/004-install-location.patch
}

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -r build-${MINGW_CHOST}
  mkdir build-${MINGW_CHOST} && cd build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_SHARED=ON \
    ../openvr-${pkgver}

  make #VERBOSE=1
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}

  make DESTDIR=${pkgdir} install
  ${MINGW_PREFIX}/bin/python ${srcdir}/cxx_header_generator.py -d "${pkgdir}${MINGW_PREFIX}/include/openvr"
  cp ${pkgdir}${MINGW_PREFIX}/include/openvr/openvr_mingw.hpp ${pkgdir}${MINGW_PREFIX}/include/openvr_mingw.hpp
  install -Dm644 "${srcdir}/openvr-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
